<template>
	<view>
		<image src="../../static/login/top.png" mode="widthFix" class="top"></image>
		<image src="../../static/login/logo.jpg" mode="widthFix" class="logo"></image>
		<view class="desc">
			<text class="name">有我在您可放心畅饮</text>
		</view>
		<button class="btn" @tap="subscribeMessage()">乘客登陆</button>
		<view class="register-container">
			没有账号?
			<text class="link" @tap="toRegisterPage()">立即注册</text>
		</view>
		<text class="remark">小程序仅限于飞驰专车代驾使用,登录前请先进行微信注册,注册前请消息阅读注册需求和使用流程</text>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			login_driver_type: 2,
		};
	},
	methods: {
		subscribeMessage() {
			const _this = this;
			wx.login({
			  success (res) {
			    if (res.code) {
					console.log(res.code);
					_this.post("/uaa/app/login/wxLogin/" + res.code + "/" + _this.login_driver_type, (resp) => {
						if (resp.success) {
							uni.showToast({
								icon: "success",
								title: "登录成功",
							});
							
							let {tokenName, tokenValue, permissions, loginInfo} = resp.data
							uni.setStorageSync("tokenName", tokenName)
							uni.setStorageSync("tokenValue", tokenValue)
							console.log(tokenValue);
							uni.setStorageSync("permissions", permissions)
							uni.setStorageSync("loginInfo", loginInfo)
							
							// 设置一个1000毫秒后执行的定时器
							setTimeout(function() {
							    //在起始页面跳转到test.vue页面并传递参数
							    uni.switchTab({
							    	url: '/pages/workbench/workbench'
							    });
							}, 2000);
						} else {
							uni.showToast({
								icon: "error",
								title: resp.message,
							});
						}				  
					})                                          
			    } else {                                      
			      console.log('登录失败！' + res.errMsg)       
			    }                                             
			  }
			})
		},
		toRegisterPage () {
			uni.navigateTo({
				url:'/pages/register/register'
			});
		}
		
	},
	onLoad: function() {}
};
</script>

<style lang="less">
@import url('login.less');
</style>
